//
//  SCBuyImmediatelyController.m
//  shangcheng
//
//  Created by 张艳江 on 2019/7/1.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCBuyImmediatelyController.h"
#import "SCSubmitOrder_EPController.h"

@interface SCBuyImmediatelyController ()

@property (weak, nonatomic) IBOutlet UIImageView *goodsImage;
@property (weak, nonatomic) IBOutlet UILabel     *nameLab;
@property (weak, nonatomic) IBOutlet UILabel     *refundTypeLab;
@property (weak, nonatomic) IBOutlet UILabel     *desLab;
@property (weak, nonatomic) IBOutlet UILabel     *dateLab;
@property (weak, nonatomic) IBOutlet UILabel     *ruleLab;
@property (weak, nonatomic) IBOutlet UILabel     *priceLab;
@property (weak, nonatomic) IBOutlet UILabel     *old_priceLab;

@property (strong, nonatomic) SCModel *model;

@end

@implementation SCBuyImmediatelyController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //请求数据
    [self requestData];
}
- (void)requestData{
    
    NSString *url = [MyTool splicingWithUrl:@"admin.php?g=System&c=EdphApp&a=food_details"];
    NSDictionary *dict = @{@"food_id":self.food_id};
    [SVProgressHUD showWithStatus:@"加载中..."];
    [[NetworkRequestTool sharedNetworkTool] POST:url parameters:dict finished:^(id result, NSString *error) {
        //NSLog(@"数据%@",result);
        [SVProgressHUD dismiss];
        self.model = [SCModel mj_objectWithKeyValues:result[@"data"]];
        
        [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://www.douyinhot.com/upload/foodshop_goods/%@",self.model.image]] placeholderImage:[UIImage imageNamed:@""]];
        self.refundTypeLab.text = self.model.rule;
        self.nameLab.text = self.model.name;
        self.desLab.text = self.model.des;
        self.dateLab.text = [NSString stringWithFormat:@"%@至%@",self.model.begn_time,self.model.end_time];
        self.ruleLab.text = self.model.is_use;
        self.priceLab.text = [NSString stringWithFormat:@"¥ %@",self.model.price];
        self.old_priceLab.text = [NSString stringWithFormat:@"¥%@",self.model.old_price];
    }];
}
#pragma mark - 立即购买
- (IBAction)clickNowBuy:(UIButton *)sender {
    
    if (Token == nil) {
        [MyTool loginWithVc:self];
        return;
    }
    SCSubmitOrder_EPController *vc = [[SCSubmitOrder_EPController alloc]init];
    vc.title = self.title;
    vc.model = self.model;
    vc.model.goods_id = self.food_id;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
